﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace V32VM
{
    public partial class SourceEditDialog : Form
    {
        private bool sourceOK { get; set; }
        private bool cancelling { get; set; }
        public Source Source { get; private set; }

        public SourceEditDialog(Source currentSource)
        {
            InitializeComponent();

            this.sourceTextBox.Text = currentSource.ToParsableString();
            sourceOK = true;
            cancelling = false;
        }

        private void okButton_Click(object sender, EventArgs e)
        {
            try
            {
                this.Source = V32VM.Source.Parse(this.sourceTextBox.Text);
                sourceOK = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Source Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                sourceOK = false;
            }
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            cancelling = true;
        }

        private void SourceEditDialog_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!sourceOK && !cancelling)
                e.Cancel = true;
        }
    }
}
